package com.woniu.map.controller;

import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.response.WeatherLiveResponse;
import com.woniu.map.remote.WeatherClient;
import com.woniu.map.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/weather")
public class WeatherController {

    @Autowired
    private WeatherService weatherService;

    /** 当前天气
     * @param city 城市编码
     * @return
     */
    @GetMapping("/live")
    public ResponseResult<List<WeatherLiveResponse>> getLiveWeather(@RequestParam("city") String city)
    {
        List weather1 = weatherService.getWeather(city, false);
        if (weather1!=null){
            return ResponseResult.success((List< WeatherLiveResponse>)weather1);
        }else
            return ResponseResult.fail(1400,"查询失败");


    }

    /**
     * 预报天气
     * @param city
     * @return
     */
    @GetMapping("/for")
    public ResponseResult<List<WeatherLiveResponse>> getForWeather(@RequestParam("city") String city) {
        List<WeatherLiveResponse> weather1 = (List<WeatherLiveResponse>)weatherService.getWeather(city, true);
       if (weather1 != null){
           return ResponseResult.success(weather1);
       }else
           return ResponseResult.fail(1400,"查询失败");
    }

}
